tableaux = 0
VenenoVenenosamenteVenenoso = false
InButton = "Fight"
OrientacionBar = "Horizontal"
ActualName = ""
KRS = 0
KRY = 20.5
KRX = 0
KRA = 0
HPEnvenenadosPorKR = 0
ContadorKRHP = 0
KRtimer = 0
letters = 0
statusPos = {320, 70.5}
CapaA = "BelowArena"

function UpdateUI() --Don't touch please. Put this function in your Update function.
	if not spawnedUI then
		Cubredor = CreateSprite("Fake UI, KR and HP Library Sprites/Barra","BelowArena")
		BtF = CreateSprite("Fake UI, KR and HP Library Sprites/FIGHT 0","BelowArena")
		BtA = CreateSprite("Fake UI, KR and HP Library Sprites/ACT 0","BelowArena")
		BtI = CreateSprite("Fake UI, KR and HP Library Sprites/ITEM 0","BelowArena")
		BtM = CreateSprite("Fake UI, KR and HP Library Sprites/MERCY 0","BelowArena")
		LV = CreateSprite("Fake UI, KR and HP Library Sprites/LV","BelowArena")
		HP = CreateSprite("Fake UI, KR and HP Library Sprites/HP","BelowArena")
		MaxHP = CreateSprite("Fake UI, KR and HP Library Sprites/Barra","BelowArena")
		BarHP = CreateSprite("Fake UI, KR and HP Library Sprites/Barra","BelowArena")
		BarKR = CreateSprite("Fake UI, KR and HP Library Sprites/Barra","BelowArena")
		Model = CreateSprite("Fake UI, KR and HP Library Sprites/Custom HP Bars/"..OrientacionBar.."/empty","BelowArena")
		KR = CreateSprite("Fake UI, KR and HP Library Sprites/KR","BelowArena")
		Name = {}
		BtF.MoveTo(87, 27)
		BtA.MoveTo(240, 27)
		BtI.MoveTo(400, 27)
		BtM.MoveTo(555, 27)
		MaxHP.yscale = 20
		MaxHP.color = {1, 0, 0}
		BarHP.yscale = 20
		BarHP.color = {1, 1, 0}
		BarKR.yscale = 20
		BarKR.color = {232/255, 0, 1}
		Cubredor.color = {0, 0, 0}
		Cubredor.Scale(640, 150)
		Cubredor.MoveTo(320, 75)
		spawnedUI = true
	end
	AuxName = Player.name
	PositionAux = 290
	for i=1,#Name do
		local sprite = Name[i - tableaux]
		sprite.MoveTo(statusPos[1] - sprite.GetVar("X") + sprite.width/2, statusPos[2])
		if sprite.GetVar("Remove") then
			sprite.Remove()
			sprite = nil
			table.remove(Name, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	if ActualName ~= AuxName then
		for i=1,#Name do
			local sprite = Name[i - tableaux]
			sprite.Remove()
			sprite = nil
			table.remove(Name, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
		letters = 0
	elseif CorrectorLet then
		PositionAux = CorrectorLet
	end
	while AuxName ~= "" and ActualName ~= AuxName do
		Letter = CreateSprite("Fake UI, KR and HP Library Sprites/Letters/"..string.upper(string.sub(AuxName,1,1)),"BelowArena")
		Letter.MoveTo(statusPos[1] - PositionAux + Letter.width/2, statusPos[2])
		Letter.SetVar("X", PositionAux)
		PositionAux = PositionAux - Letter.width - 3
		table.insert(Name, Letter)
		AuxName = string.sub(AuxName, 2)
		ActualName = Player.name
		CorrectorLet = PositionAux
		letters = letters + 1
	end
	PositionAux = PositionAux - 28
	LV.MoveTo(statusPos[1] - PositionAux + LV.width/2, statusPos[2])
	PositionAux = PositionAux - 44
	if not NumberLV then
		NumberLV = CreateSprite("Fake UI, KR and HP Library Sprites/0","BelowArena")
	end
	if NumberLVP then
		NumberLVP.Remove()
		NumberLVP = nil
	end
	if not CustomLenghtBar then
		if Player.lv >= 10 then
			NumberLVP = CreateSprite("Fake UI, KR and HP Library Sprites/"..(Player.lv-Player.lv%10)/10,CapaA)
		end
		NumberLV.Set("Fake UI, KR and HP Library Sprites/"..Player.lv%10)
	else
		if FakeLV >= 10 then
			NumberLVP = CreateSprite("Fake UI, KR and HP Library Sprites/"..(FakeLV-FakeLV%10)/10,CapaA)
		end
		NumberLV.Set("Fake UI, KR and HP Library Sprites/"..FakeLV%10)
	end
	if NumberLVP then
		NumberLVP.MoveTo(statusPos[1] - PositionAux + NumberLVP.width/2, statusPos[2])
		PositionAux = PositionAux - NumberLVP.width - 3
	end
	NumberLV.MoveTo(statusPos[1] - PositionAux + NumberLV.width/2, statusPos[2])
	if letters <= 6 then
		PositionAux = 75
	else
		PositionAux = 4
	end
	HP.MoveTo(statusPos[1] - PositionAux + HP.width/2, statusPos[2] - 0.5)
	PositionAux = PositionAux - HP.width - 8
	HPEnvenenadosPorKR = math.min(HPEnvenenadosPorKR, Player.hp - 1)
	if HPEnvenenadosPorKR > 0 and Player.hp <= 1 then
		HPEnvenenadosPorKR = 0
		Player.hp = 1
	elseif HPEnvenenadosPorKR > 0 and not ReposicionandoHP and Player.hp > 1 then
		ContadorKRHP = ContadorKRHP + 1
		if HPEnvenenadosPorKR >= 30 then
			if ContadorKRHP >= 8 then
				HPEnvenenadosPorKR = math.max(HPEnvenenadosPorKR - 1, 0)
				Player.hp = Player.hp - 1
				ContadorKRHP = 0
			end
		elseif HPEnvenenadosPorKR >= 20 then
			if ContadorKRHP >= 15 then
				HPEnvenenadosPorKR = math.max(HPEnvenenadosPorKR - 1, 0)
				Player.hp = Player.hp - 1
				ContadorKRHP = 0
			end
		elseif HPEnvenenadosPorKR >= 10 then
			if ContadorKRHP >= 30 then
				HPEnvenenadosPorKR = math.max(HPEnvenenadosPorKR - 1, 0)
				Player.hp = Player.hp - 1
				ContadorKRHP = 0
			end
		else
			if ContadorKRHP >= 60 then
				HPEnvenenadosPorKR = math.max(HPEnvenenadosPorKR - 1, 0)
				Player.hp = Player.hp - 1
				ContadorKRHP = 0
			end
		end
	elseif ReposicionandoHP then
		ReposicionandoHP = nil
	end
	if OrientacionBar == "Horizontal" then
		if not CustomLenghtBar then
			if Player.lv <= 20 then
				MaxHP.xscale = 19
				for i=1,Player.lv do
					if i ~= 4 and i ~= 9 and i ~= 14 and i < 17 then
						MaxHP.xscale = MaxHP.xscale + 5
					elseif i == 17 then
						MaxHP.xscale = MaxHP.xscale + 6
					elseif i == 20 then
						MaxHP.xscale = MaxHP.xscale + 9
					else
						MaxHP.xscale = MaxHP.xscale + 4
					end
				end
				if Player.lv == 20 then
					BarHP.xscale = MaxHP.xscale/(19 + 4*Player.lv)*Player.hp
					BarKR.xscale = MaxHP.xscale/(19 + 4*Player.lv)*HPEnvenenadosPorKR
				else
					BarHP.xscale = MaxHP.xscale/(16 + 4*Player.lv)*Player.hp
					BarKR.xscale = MaxHP.xscale/(16 + 4*Player.lv)*HPEnvenenadosPorKR
				end
			else
				MaxHP.xscale = 120
				BarHP.xscale = 120/(19 + 4*Player.lv)*Player.hp
				BarKR.xscale = 120/(19 + 4*Player.lv)*HPEnvenenadosPorKR
			end
		else
			MaxHP.xscale = CustomLenghtBar
			BarHP.xscale = CustomLenghtBar/CustomHP*Player.hp
			BarKR.xscale = CustomLenghtBar/CustomHP*HPEnvenenadosPorKR
		end
	elseif OrientacionBar == "Vertical" then
		MaxHP.xscale = 20
		BarHP.xscale = 20
		BarKR.xscale = 20
		if Player.lv >= 20 then
			BarHP.yscale = MaxHP.yscale/(19 + 4*Player.lv)*Player.hp
			BarKR.yscale = MaxHP.yscale/(19 + 4*Player.lv)*HPEnvenenadosPorKR
		else
			BarHP.yscale = MaxHP.yscale/(16 + 4*Player.lv)*Player.hp
			BarKR.yscale = MaxHP.yscale/(16 + 4*Player.lv)*HPEnvenenadosPorKR
		end
	end
	Model.MoveTo(statusPos[1] - PositionAux + Model.width/2, statusPos[2] - 1)
	MaxHP.MoveTo(statusPos[1] - PositionAux + MaxHP.xscale/2, statusPos[2] - 1)
	BarHP.MoveTo(statusPos[1] - PositionAux + BarHP.xscale/2, statusPos[2] - 11 + BarHP.yscale/2)
	if OrientacionBar == "Horizontal" then
		BarKR.MoveTo(statusPos[1] - PositionAux + BarHP.xscale - BarKR.xscale/2, statusPos[2] - 1)
	elseif OrientacionBar == "Vertical" then
		BarKR.MoveTo(statusPos[1] - PositionAux + BarHP.xscale - BarKR.xscale/2, statusPos[2] - 11 + BarHP.yscale - BarKR.yscale/2)
	end
	if KRAppear then
		if KRAppear == "Appear" then
			KRtimer = KRtimer + 1
			KRA = math.sin(math.rad(90/30*KRtimer))
			KRX = 33*math.sin(math.rad(90/30*KRtimer))
			KRY = 20.5 - 21*math.sin(math.rad(90/30*KRtimer))
			if KRtimer >= 30 then
				KRAppear = nil
			end
		elseif KRAppear == "Disappear" then
			KRtimer = KRtimer + 1
			KRS = 1 + 2/30*KRtimer
			KRA = 1 - math.sin(math.rad(90/30*KRtimer))
			KRX = 33 - 33*math.sin(math.rad(90/30*KRtimer))
			if KRtimer >= 30 then
				KRAppear = nil
			end
		end
	end
	KR.MoveTo(statusPos[1] - PositionAux + math.max(MaxHP.xscale, BarHP.xscale) + 10 + KR.width/2, statusPos[2] + KRY)
	PositionAux = PositionAux - KRX
	KR.alpha = KRA
	KR.Scale(KRS, KRS)
	PositionAux = PositionAux - math.max(MaxHP.xscale, BarHP.xscale) - 14
	if HPEnvenenadosPorKR > 0 then
		ColorAux = {232/255, 0, 1}
	else
		ColorAux = {1, 1, 1}
	end
	if not NumberCHP1 then
		NumberCHP1 = CreateSprite("Fake UI, KR and HP Library Sprites/0","BelowArena")
	end
	if not NumberCHP2 then
		NumberCHP2 = CreateSprite("Fake UI, KR and HP Library Sprites/0","BelowArena")
	end
	if not Slash then
		Slash = CreateSprite("Fake UI, KR and HP Library Sprites/Slash","BelowArena")
	end
	if Player.hp >= 100 then
		NumberEC = CreateSprite("Fake UI, KR and HP Library Sprites/"..(Player.hp-Player.hp%100)/100,CapaA)
		NumberEC.MoveTo(statusPos[1] - PositionAux + NumberEC.width/2, statusPos[2])
		NumberEC.SetVar("X", PositionAux)
		NumberEC.color = ColorAux
		table.insert(Name, NumberEC)
		NumberEC.SetVar("Remove", true)
		PositionAux = PositionAux - NumberEC.width - 3
	end
	NumberCHP1.Set("Fake UI, KR and HP Library Sprites/"..(Player.hp%100-Player.hp%10)/10)
	NumberCHP1.MoveTo(statusPos[1] - PositionAux + NumberCHP1.width/2, statusPos[2])
	NumberCHP1.color = ColorAux
	PositionAux = PositionAux - NumberCHP1.width - 3
	NumberCHP2.Set("Fake UI, KR and HP Library Sprites/"..Player.hp%10)
	NumberCHP2.MoveTo(statusPos[1] - PositionAux + NumberCHP2.width/2, statusPos[2])
	NumberCHP2.color = ColorAux
	PositionAux = PositionAux - NumberCHP2.width - 17
	Slash.MoveTo(statusPos[1] - PositionAux + Slash.width/2, statusPos[2])
	Slash.color = ColorAux
	PositionAux = PositionAux - Slash.width - 17
	if not NumberMHP1 then
		NumberMHP1 = CreateSprite("Fake UI, KR and HP Library Sprites/0","BelowArena")
	end
	if not NumberMHP2 then
		NumberMHP2 = CreateSprite("Fake UI, KR and HP Library Sprites/0","BelowArena")
	end
	if not CustomLenghtBar then
		if Player.lv >= 20 then
			if Player.lv > 20 then
				NumberEM = CreateSprite("Fake UI, KR and HP Library Sprites/"..((19 + 4*Player.lv)-(19 + 4*Player.lv)%100)/100,"BelowArena")
				NumberEM.MoveTo(statusPos[1] - PositionAux + NumberEM.width/2, statusPos[2])
				NumberEM.SetVar("X", PositionAux)
				NumberEM.color = ColorAux
				table.insert(Name, NumberEM)
				NumberEM.SetVar("Remove", true)
				PositionAux = PositionAux - NumberEM.width - 3
			end
			NumberMHP1.Set("Fake UI, KR and HP Library Sprites/"..((19 + 4*Player.lv)%100-(19 + 4*Player.lv)%10)/10)
			NumberMHP1.MoveTo(statusPos[1] - PositionAux + NumberMHP1.width/2, statusPos[2])
			NumberMHP1.color = ColorAux
			PositionAux = PositionAux - NumberMHP1.width - 3
			NumberMHP2.Set("Fake UI, KR and HP Library Sprites/"..(19 + 4*Player.lv)%10)
			NumberMHP2.MoveTo(statusPos[1] - PositionAux + NumberMHP2.width/2, statusPos[2])
			NumberMHP2.color = ColorAux
		else
			NumberMHP1.Set("Fake UI, KR and HP Library Sprites/"..((16 + 4*Player.lv)%100-(16 + 4*Player.lv)%10)/10)
			NumberMHP1.MoveTo(statusPos[1] - PositionAux + NumberMHP1.width/2, statusPos[2])
			NumberMHP1.color = ColorAux
			PositionAux = PositionAux - NumberMHP1.width - 3
			NumberMHP2.Set("Fake UI, KR and HP Library Sprites/"..(16 + 4*Player.lv)%10)
			NumberMHP2.MoveTo(statusPos[1] - PositionAux + NumberMHP2.width/2, statusPos[2])
			NumberMHP2.color = ColorAux
		end
	else
		if CustomHP >= 100 then
			NumberEM = CreateSprite("Fake UI, KR and HP Library Sprites/"..(CustomHP-CustomHP%100)/100,"BelowArena")
			NumberEM.MoveTo(statusPos[1] - PositionAux + NumberEM.width/2, statusPos[2])
			NumberEM.SetVar("X", PositionAux)
			NumberEM.color = ColorAux
			table.insert(Name, NumberEM)
			NumberEM.SetVar("Remove", true)
			PositionAux = PositionAux - NumberEM.width - 3
		end
		NumberMHP1.Set("Fake UI, KR and HP Library Sprites/"..(CustomHP%100-CustomHP%10)/10)
		NumberMHP1.MoveTo(statusPos[1] - PositionAux + NumberMHP1.width/2, statusPos[2])
		NumberMHP1.color = ColorAux
		PositionAux = PositionAux - NumberMHP1.width - 3
		NumberMHP2.Set("Fake UI, KR and HP Library Sprites/"..CustomHP%10)
		NumberMHP2.MoveTo(statusPos[1] - PositionAux + NumberMHP2.width/2, statusPos[2])
		NumberMHP2.color = ColorAux
	end
	if Black then
		Black.MoveTo(Model.x + Black.xscale/2 - Model.width/2 - 34, Model.y)
		if Black.GetVar("remove") then
			Black.alpha = Black.alpha - 0.02
			if Black.alpha <= 0 then
				Black.Remove()
				Black = nil
			end
		else
			Black.alpha = Black.alpha + 0.02
			if Black.alpha >= 1 then
				Black.SetVar("remove", true)
				OrientacionBar = Direccionador
				Direccionador = nil
				Model.Set("Fake UI, KR and HP Library Sprites/Custom HP Bars/"..OrientacionBar.."/"..ModelodelaBarraHP)
				ModelodelaBarraHP = nil
			end
		end
	end
	if FrameWait then
		Player.sprite.alpha = 1
		FrameWait = nil
		if Player.absy == 25 then
			if Player.absx == 48 then
				InButton = "Fight"
			elseif Player.absx == 202 then
				InButton = "Act"
			elseif Player.absx == 361 then
				InButton = "Item"
			elseif Player.absx == 515 then
				InButton = "Mercy"
			end
		end
	end
	if SelectingAction then
		if InButton == "Fight" then
			BtF.Set("Fake UI, KR and HP Library Sprites/FIGHT 1")
			BtA.Set("Fake UI, KR and HP Library Sprites/ACT 0")
			BtI.Set("Fake UI, KR and HP Library Sprites/ITEM 0")
			BtM.Set("Fake UI, KR and HP Library Sprites/MERCY 0")
			Player.MoveToAbs(BtF.x - 39*math.cos(math.rad(BtF.rotation)) + 2*math.sin(math.rad(BtF.rotation)), BtF.y - 2*math.cos(math.rad(BtF.rotation)) - 39*math.sin(math.rad(BtF.rotation)), true)
			Player.sprite.rotation = BtF.rotation
			PlayerPosition = {BtF.x - 39*math.cos(math.rad(BtF.rotation)) + 2*math.sin(math.rad(BtF.rotation)), BtF.y - 2*math.cos(math.rad(BtF.rotation)) - 39*math.sin(math.rad(BtF.rotation))}
			if Input.Left == 1 then
				Player.sprite.alpha = 0
				FrameWait = true
			elseif Input.Right == 1 then
				Player.sprite.alpha = 0
				FrameWait = true
			end
		elseif InButton == "Act" then
			BtF.Set("Fake UI, KR and HP Library Sprites/FIGHT 0")
			BtA.Set("Fake UI, KR and HP Library Sprites/ACT 1")
			BtI.Set("Fake UI, KR and HP Library Sprites/ITEM 0")
			BtM.Set("Fake UI, KR and HP Library Sprites/MERCY 0")
			Player.MoveToAbs(BtA.x - 38*math.cos(math.rad(BtA.rotation)) + 2*math.sin(math.rad(BtA.rotation)), BtA.y - 2*math.cos(math.rad(BtA.rotation)) - 38*math.sin(math.rad(BtA.rotation)), true)
			Player.sprite.rotation = BtA.rotation
			PlayerPosition = {BtA.x - 38*math.cos(math.rad(BtA.rotation)) + 2*math.sin(math.rad(BtA.rotation)), BtA.y - 2*math.cos(math.rad(BtA.rotation)) - 38*math.sin(math.rad(BtA.rotation))}
			if Input.Left == 1 then
				Player.sprite.alpha = 0
				FrameWait = true
			elseif Input.Right == 1 then
				Player.sprite.alpha = 0
				FrameWait = true
			end
		elseif InButton == "Item" then
			BtF.Set("Fake UI, KR and HP Library Sprites/FIGHT 0")
			BtA.Set("Fake UI, KR and HP Library Sprites/ACT 0")
			BtI.Set("Fake UI, KR and HP Library Sprites/ITEM 1")
			BtM.Set("Fake UI, KR and HP Library Sprites/MERCY 0")
			Player.MoveToAbs(BtI.x - 39*math.cos(math.rad(BtI.rotation)) + 2*math.sin(math.rad(BtI.rotation)), BtI.y - 2*math.cos(math.rad(BtI.rotation)) - 39*math.sin(math.rad(BtI.rotation)), true)
			Player.sprite.rotation = BtI.rotation
			PlayerPosition = {BtI.x - 39*math.cos(math.rad(BtI.rotation)) + 2*math.sin(math.rad(BtI.rotation)), BtI.y - 2*math.cos(math.rad(BtI.rotation)) - 39*math.sin(math.rad(BtI.rotation))}
			if Input.Left == 1 then
				Player.sprite.alpha = 0
				FrameWait = true
			elseif Input.Right == 1 then
				Player.sprite.alpha = 0
				FrameWait = true
			end
		elseif InButton == "Mercy" then
			BtF.Set("Fake UI, KR and HP Library Sprites/FIGHT 0")
			BtA.Set("Fake UI, KR and HP Library Sprites/ACT 0")
			BtI.Set("Fake UI, KR and HP Library Sprites/ITEM 0")
			BtM.Set("Fake UI, KR and HP Library Sprites/MERCY 1")
			Player.MoveToAbs(BtM.x - 40*math.cos(math.rad(BtM.rotation)) + 2*math.sin(math.rad(BtM.rotation)), BtM.y - 2*math.cos(math.rad(BtM.rotation)) - 40*math.sin(math.rad(BtM.rotation)), true)
			Player.sprite.rotation = BtM.rotation
			PlayerPosition = {BtM.x - 40*math.cos(math.rad(BtM.rotation)) + 2*math.sin(math.rad(BtM.rotation)), BtM.y - 2*math.cos(math.rad(BtM.rotation)) - 39*math.sin(math.rad(BtM.rotation))}
			if Input.Left == 1 then
				Player.sprite.alpha = 0
				FrameWait = true
			elseif Input.Right == 1 then
				Player.sprite.alpha = 0
				FrameWait = true
			end
		end
	end
end

function UpdateStatesUI(new, old) --Don't touch please. Put this function in your EnteringState(newstate, oldstate) function, and put those 2 variables in this function too. Example: you have EnteringState(A, B) then put inside of that function UpdateStatesUI(A, B).
	if (new == "DIALOGRESULT" or new == "ATTACKING" or new == "ENEMYDIALOGUE") and spawnedUI then
		ResetButtons()
	end
	if new == "ACTIONSELECT" then
		SelectingAction = true
		FrameWait = true
	elseif old == "ACTIONSELECT" then
		SelectingAction = nil
		Player.sprite.rotation = 0
	end
end

function HPColor(Color)
	if not BarHP then
		ReposicionandoHP = true
		UpdateUI()
	end
	BarHP.color = Color
end

function SetStatusDefaultPosition() --Reset the Status coordenates.
	statusPos = {320, 70.5}
end

function StatusMoveTo(x, y) --Move the all the Status to x and y coordenates.
	statusPos = {x, y}
	ReposicionandoHP = true
	UpdateUI()
end

function AddKR(amount) --Only in Waves or Hurting things.
	if VenenoVenenosamenteVenenoso then
		HPEnvenenadosPorKR = math.min(HPEnvenenadosPorKR + amount, Player.hp - 1)
	else
		error("\n\nYou can't add "..amount.." KR when the KR effect isn't active, activate the KR effect before adding KR please:\n\nConfigutation(bool setKR, bool animateAppearing):\n- setKR: only true or false to activate or deactivate.\n- animateAppearing: set it to true to animate the appearing or desappearing of the KR, set it to false to make appear the KR immeadiate.\n\nTHANKS FOR READING AND USING MY LIBRARY!\n\nSincerely: Cezar Andrade")
	end
end

function ConfigurateKR(setKR, animateAppearing) --Set the KR effect with this.
	if KRAppear then
		error("\n\nPlease wait until the animation of the appearing or disappearing of the KR effect is done to configurate the KR effect again, the animation lasts about 30 frames, so check your code and be sure you left 30 frames of difference between the configurations.\n\nTHANKS FOR READING AND USING MY LIBRARY!\n\nSincerely: Cezar Andrade")
	else
		if setKR == true and not VenenoVenenosamenteVenenoso then
			VenenoVenenosamenteVenenoso = true
			if animateAppearing == true then
				KRS = 1
				KRY = 20.5
				KRX = 0
				KRA = 0
				KRAppear = "Appear"
				KRtimer = 0
			else
				KRS = 1
				KRY = -0.5
				KRX = 33
				KRA = 1
			end
		elseif setKR == false and VenenoVenenosamenteVenenoso then
			VenenoVenenosamenteVenenoso = nil
			if animateAppearing == true then
				KRS = 1
				KRY = -0.5
				KRX = 33
				KRA = 1
				KRAppear = "Disappear"
				KRtimer = 0
			else
				KRS = 0
				KRY = 20.5
				KRX = 0
				KRA = 0
			end
		end
	end
end

function SetDefaultHP(LV, initialHP) --Deactivates the fake HP Bar and his MaxHP too to return on the basic HP Bar.
	if type(LV) == "number" and type(initialHP) == "number" then
		Player.lv = LV
		Player.hp = 10000000
		if Player.lv < 20 then
			Player.setMaxHPShift(16 + 4*Player.lv, 1.7, true, true, false)
		else
			Player.setMaxHPShift(19 + 4*Player.lv, 1.7, true, true, false)
		end
		Player.hp = initialHP
		CustomLenghtBar = nil
		CustomHP = nil
	else
		error("\n\nLook at your code where you put this function, you coded something wrong:\n\nSetDefauultHP(int LV, int initialHP)\n-LV: sets the Player.lv (only integer numbers).\n-initialHP: sets the Player.hp (only integer numbers).\n\nTHANKS FOR READING AND USING MY LIBRARY!\n\nSincerely: Cezar Andrade")
	end
end

function SetCustomHP(lenght, fakeLV, maxhp, initialHP, canHeal) --With this you can set a fake HP Bar with the width you want (it have limits), and you can set the MaxHP of the Player too.
	if type(lenght) == "number" and type(fakeLV) == "number" and type(maxhp) == "number" and type(initialHP) == "number" and type(canHeal) == "boolean" then
		if lenght > 0 and fakeLV >= 0 and maxhp > 0 and initialHP > 0 then
			Player.lv = 1
			FakeLV = fakeLV
			if letters <= 6 then
				CustomLenghtBar = math.min(lenght, 260)
			else
				CustomLenghtBar = math.min(lenght, 180)
			end
			CustomHP = maxhp
			Player.setMaxHPShift(maxhp, 1.7, true, canHeal, false)
			Player.hp = initialHP
		else
			error("\n\nYou can't put negative numbers in this function:\n\nSetCustomHP(int lenght, int fakeLV, int maxhp, int initialHP, bool canHeal)\n-lenght: Only positive numbers.\n-fakeLV: 0 and positive numbers.\n-maxhp: Only positive numbers.\n-initialHP: Only positive numbers.\n-canHeal: only true or false.\n\nTHANKS FOR READING AND USING MY LIBRARY!\n\nSincerely: Cezar Andrade")
		end
	else
		error("\n\nLook at your code where you put this function, you coded something wrong:\n\nSetCustomHP(int lenght, int fakeLV, int maxhp, int initialHP, bool canHeal)\n-lenght: set the width of the HP bar (only integer numbers).\n-fakeLV: set a fake sprite of the Player LV (max 99, doesn't affect in the HP, only integer numbers).\n-maxhp: sets the max HP that the player can have (LV doesn't matter, only integer numbers).\n-initialHP: sets the Player.hp (only integer numbers).\n-canHeal: set to true if you want the player can heal his max hp, otherwise false.\n\nTHANKS FOR READING AND USING MY LIBRARY!\n\nSincerely: Cezar Andrade")
	end
end

function ResetButton(which) --Reset the coordenates and rotation of a Button.
	if which == "FIGHT" or which == "Fight" or which == "fight" then
		BtF.MoveTo(87, 27)
		BtF.rotation = 0
	elseif which == "ACT" or which == "Act" or which == "act" then
		BtA.MoveTo(240, 27)
		BtA.rotation = 0
	elseif which == "ITEM" or which == "Item" or which == "item" then
		BtI.MoveTo(400, 27)
		BtI.rotation = 0
	elseif which == "MERCY" or which == "Mercy" or which == "mercy" then
		BtM.MoveTo(555, 27)
		BtM.rotation = 0
	else
		error("\n\nYou need to indicate which button you will move to its default coordenates, verify your code:\n\nResetButton(string whichButton)\n- whichButton: \"FIGHT\", \"Fight\" or \"fight\" to select the Fight Button,\n \"ACT\", \"Act\" or \"act\" to select the Act Button,\n \"ITEM\", \"Item\" or \"item\" to select the Item Button,\n \"MERCY\", \"Mercy\" or \"mercy\" to select the Mercy Button\n\nTHANKS FOR READING AND USING MY LIBRARY!\n\nSincerely: Cezar Andrade")
	end
end

function ButtonMoveTo(which, x, y) --Move a Button where you want.
	if which == "FIGHT" or which == "Fight" or which == "fight" then
		BtF.MoveTo(x, y)
	elseif which == "ACT" or which == "Act" or which == "act" then
		BtA.MoveTo(x, y)
	elseif which == "ITEM" or which == "Item" or which == "item" then
		BtI.MoveTo(x, y)
	elseif which == "MERCY" or which == "Mercy" or which == "mercy" then
		BtM.MoveTo(x, y)
	else
		error("\n\nYou need to indicate which button you will MoveTo x and y coordenates, verify your code:\n\nButtonMoveTo(string whichButton, int x, int y)\n- whichButton: \"FIGHT\", \"Fight\" or \"fight\" to select the Fight Button,\n \"ACT\", \"Act\" or \"act\" to select the Act Button,\n \"ITEM\", \"Item\" or \"item\" to select the Item Button,\n \"MERCY\", \"Mercy\" or \"mercy\" to select the Mercy Button\n- x: X coordenates\n- y: Y coordenates\n\nTHANKS FOR READING AND USING MY LIBRARY!\n\nSincerely: Cezar Andrade")
	end
end

function ChangeModelBarHP(modelo) --Change the Model of the HP bar.
	if not Model then
		ReposicionandoHP = true
		UpdateUI()
	end
	if modelo.Mask ~= "Remove" then
		if modelo.Animation then
			modelo.Animation = nil
			ModelodelaBarraHP = modelo.Mask
			Direccionador = modelo.Direction
			Black = CreateSprite("Fake UI, KR and HP Library Sprites/Barra","BelowArena")
			Black.color = {0, 0, 0}
			Black.Scale(400, 30)
			Black.alpha = 0
		else
			OrientacionBar = modelo.Direction
			Model.Set("Fake UI, KR and HP Library Sprites/Custom HP Bars/"..OrientacionBar.."/"..modelo.Mask)
		end
	else
		if modelo.Animation then
			modelo.Animation = nil
			ModelodelaBarraHP = "empty"
			Direccionador = modelo.Direction
			Black = CreateSprite("Fake UI, KR and HP Library Sprites/Barra","BelowArena")
			Black.color = {0, 0, 0}
			Black.Scale(400, 30)
			Black.alpha = 0
		else
			OrientacionBar = modelo.Direction
			Model.Set("Fake UI, KR and HP Library Sprites/Custom HP Bars/Horizontal/empty")
		end
	end
end

function RotateButton(which, rot) --Rotate a Button.
	if which == "FIGHT" or which == "Fight" or which == "fight" then
		BtF.rotation = rot
	elseif which == "ACT" or which == "Act" or which == "act" then
		BtA.rotation = rot
	elseif which == "ITEM" or which == "Item" or which == "item" then
		BtI.rotation = rot
	elseif which == "MERCY" or which == "Mercy" or which == "mercy" then
		BtM.rotation = rot
	else
		error("\n\nYou need to indicate which button you will rotate, verify your code:\n\nRotateButton(string whichButton, int rotation)\n- whichButton: \"FIGHT\", \"Fight\" or \"fight\" to select the Fight Button,\n \"ACT\", \"Act\" or \"act\" to select the Act Button,\n \"ITEM\", \"Item\" or \"item\" to select the Item Button,\n \"MERCY\", \"Mercy\" or \"mercy\" to select the Mercy Button\n- rotation: sets rotation in the button.\n\nTHANKS FOR READING AND USING MY LIBRARY!\n\nSincerely: Cezar Andrade")
	end
end

function ResetButtons() --Don't touch please...
	BtF.Set("Fake UI, KR and HP Library Sprites/FIGHT 0")
	BtA.Set("Fake UI, KR and HP Library Sprites/ACT 0")
	BtI.Set("Fake UI, KR and HP Library Sprites/ITEM 0")
	BtM.Set("Fake UI, KR and HP Library Sprites/MERCY 0")
end

function RelayerUI(capa) --Use this function to order your layers and the layers of the Fake UI.
	ReposicionandoHP = true
	UpdateUI()
	BtF.layer = "Bottom"
	BtA.layer = "Bottom"
	BtI.layer = "Bottom"
	BtM.layer = "Bottom"
	LV.layer = "Bottom"
	HP.layer = "Bottom"
	MaxHP.layer = "Bottom"
	BarHP.layer = "Bottom"
	BarKR.layer = "Bottom"
	Model.layer = "Bottom"
	KR.layer = "Bottom"
	for i=1,#Name do
		Name[i].layer = "Bottom"
	end
	if NumberLVP then
		NumberLVP.layer = "Bottom"
	end
	NumberLV.layer = "Bottom"
	if NumberEC and NumberEC.isactive then
		NumberEC.layer = "Bottom"
	end
	NumberCHP1.layer = "Bottom"
	NumberCHP2.layer = "Bottom"
	Slash.layer = "Bottom"
	if NumberEM and NumberEM.isactive then
		NumberEM.layer = "Bottom"
	end
	NumberMHP1.layer = "Bottom"
	NumberMHP2.layer = "Bottom"
	if Black then
		Black.layer = "Bottom"
	end
	BtF.layer = capa
	BtA.layer = capa
	BtI.layer = capa
	BtM.layer = capa
	LV.layer = capa
	HP.layer = capa
	MaxHP.layer = capa
	BarHP.layer = capa
	BarKR.layer = capa
	Model.layer = capa
	KR.layer = capa
	for i=1,#Name do
		Name[i].layer = capa
	end
	if NumberLVP then
		NumberLVP.layer = capa
	end
	NumberLV.layer = capa
	if NumberEC and NumberEC.isactive then
		NumberEC.layer = capa
	end
	NumberCHP1.layer = capa
	NumberCHP2.layer = capa
	Slash.layer = capa
	if NumberEM and NumberEM.isactive then
		NumberEM.layer = capa
	end
	NumberMHP1.layer = capa
	NumberMHP2.layer = capa
	if Black then
		Black.layer = capa
	end
	CapaA = capa
end